package com.weifly.jettycn.control;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.weifly.jettycn.util.CallResult;

/**
 * 控制台主页面
 * 
 * @author wei
 * @date 2011-10-05
 */
@Controller
public class ConsoleLogic extends AbstractLogic {

	/**
	 * 主页面
	 */
	@RequestMapping("/console/main.do")
	public ModelAndView main(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("console/main");
	}
	
	@RequestMapping("/console/headPage.do")
	public ModelAndView headPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("console/headPage");
	}
	
	@RequestMapping("/console/leftPage.do")
	public ModelAndView leftPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("console/leftPage");
	}
	
	@RequestMapping("/console/centerPage.do")
	public ModelAndView centerPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("console/centerPage");
	}
	
	@RequestMapping("/console/footerPage.do")
	public ModelAndView footerPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("console/footerPage");
	}

	@RequestMapping("/login.do")
	public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("console/login");
	}
	
	@RequestMapping("/checkUser.do")
	public ModelAndView checkUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
		CallResult result = new CallResult();
		
		String user = request.getParameter("user_name");
		String pass = request.getParameter("user_password");
		
		if(StringUtils.isBlank(user)){
			result.setSuccess(false);
			result.addMessage("用户名称为空");
			this.writeAjaxObject(response, result);
			return null;
		}
		
		if(StringUtils.isBlank(pass)){
			result.setSuccess(false);
			result.addMessage("用户密码为空");
			this.writeAjaxObject(response, result);
			return null;
		}
		
		if(user.equals("weijx") && pass.equals("qwer1234")){
			request.getSession().setAttribute("userInfo", new Object());
			this.writeAjaxObject(response, result);
			return null;
		}else{
			result.setSuccess(false);
			result.addMessage("登录失败");
			this.writeAjaxObject(response, result);
			return null;
		}
		
	}
}
